package com.wanxi.service.impl;

import com.wanxi.dao.ProductDao;
import com.wanxi.dao.impl.ProductImpl;
import com.wanxi.model.ProductModel;
import com.wanxi.model.ResultModel;
import com.wanxi.service.ProductService;

public class ProductServiceImpl implements ProductService {
    private ProductDao productDao = new ProductImpl();

    @Override
    public ResultModel add(ProductModel productModel) {
//        ProductDao productDao = new ProductImpl();
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(productDao.add(productModel));
//        return resultModel;
        return ResultModel.getResult(productDao.add(productModel));
    }

    @Override
    public ResultModel enable(ProductModel productModel) {
//        ProductDao productDao = new ProductImpl();
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(productDao.enable(productModel));
//        return resultModel;
        return ResultModel.getResult(productDao.enable(productModel));
    }

    @Override
    public ResultModel update(ProductModel productModel) {
//        ProductDao productDao = new ProductImpl();
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(productDao.update(productModel));
//        return resultModel;
        return ResultModel.getResult(productDao.update(productModel));
    }

    @Override
    public ResultModel delete(ProductModel productModel) {
        return ResultModel.getResult(productDao.delete(productModel));
    }

    @Override
    public ResultModel findById(ProductModel productModel) {
        return ResultModel.getResult(productDao.findById(productModel));
    }

    @Override
    public ResultModel findAll(ProductModel productModel) {
        return ResultModel.getResult(productDao.findAll(productModel), productDao.count(productModel));
    }

    @Override
    public ResultModel count(ProductModel productModel) {
        return ResultModel.getResult(productDao.count(productModel));
    }
}
